package com.gbq.util;


import lombok.extern.slf4j.Slf4j;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
public class BaseUtils {


    public static Integer Str2Int(String str){
        Integer res;
        if (str.equals("")){
            res = 0;
        }else{
            res = Integer.parseInt(str);
        }
        return res;
    }

    public static List<String> getAllKey(Map map){

        List<String> list = new ArrayList<>();
        Map<String,Object> hashMap = map;
        Set set = hashMap.keySet();
        Iterator iter = set.iterator();
        while (iter.hasNext()) {
            String key = (String) iter.next();
            list.add(key);
        }

        return list;
    }

    public static int isTable(String tablelists,String tablename){
        return tablelists.indexOf(tablename);
    }

    public static Date strToDate(String time){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;

        log.info(time);
        try {
            date = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date;
    }
}
